package es

import (
	"context"
	"fmt"
)

// 索引操作

// CreateIndex 创建索引
func CreateIndex(indexName string) error {
	resp, err := EsClient.Indices.Create(indexName).Do(context.Background())
	if err != nil {
		fmt.Println("create index failed, err:%v\n", err)
		return err
	}
	fmt.Printf("index:%#v\n", resp.Index)
	return nil
}

// DeleteIndex 删除索引
func DeleteIndex(indexName string) error {
	_, err := EsClient.Indices.Delete(indexName).Do(context.Background())
	if err != nil {
		fmt.Println("delete index failed,err:%v\n", err)
		return err
	}
	fmt.Println("delete index successed, indexName:%s", indexName)
	return nil
}
